package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Car;
import cn.wolfcode.crm.query.CarQuery;
import cn.wolfcode.crm.service.ICarService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/car")
public class CarController {
    @Autowired
    private ICarService carService;

    //视图
    @RequestMapping("/view")
    public String index() {
        return "information/car";
    }


    //查询所有
    @RequestMapping("/selectAll")
    @ResponseBody
    public Object selectAll() {
        return carService.listAll();
    }

    @RequestMapping("/query")
    @ResponseBody
    public Object query(CarQuery qo) {
        return carService.query(qo);
    }

    //新增/编辑
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Car entity) {
        try {
            carService.saveOrUpdate(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
            return new JsonResult().mark(ex.getMessage());
        }
        return new JsonResult();
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        carService.delete(id);
        return new JsonResult();
    }

    //根据保单id查询车辆信息
    @RequestMapping("selectByInsureId")
    @ResponseBody
    public Car selectByInsureId(Long insureId){
        return carService.selectByInsureId(insureId);
    }
}
